package org.summer.generator;

/**
 * 字符串工具类
 */
public class StringUtil {

    /**
     * 字符串首字母大写转换
     */
    public static String firstLetterUpperCase(String str){
        if (str == null || str.isEmpty()) {
            return str;
        }
        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
    }

    /**
     * 字符串首字母小写
     */
    public static String firstLetterLowerCase(String str){
        if (str == null || str.isEmpty()) {
            return str;
        }
        return Character.toLowerCase(str.charAt(0)) + str.substring(1);
    }
    /**
     * 字符串下划线转大驼峰
     */
    public static String underlineCaseUpperCamel(String str){
        if(str == null || str.isEmpty()){
            return str;
        }
        String[] items = str.split("_");
        if(items.length == 1){
            return firstLetterUpperCase(str);
        }
        String res = "";
        for (int i = 0; i < items.length; i++) {
            res = res + firstLetterUpperCase(items[i]);
        }
        return res;
    }
    /**
     * 字符串下划线转小驼峰
     */
    public static String underlineCaseLowerCamel(String str){
        if(str == null || str.isEmpty()){
            return str;
        }
        String[] items = str.split("_");
        if(items.length == 1){
            return str;
        }
        String res = items[0];
        for (int i = 1; i < items.length; i++) {
            res = res + firstLetterUpperCase(items[i]);
        }
        return res;
    }
}
